import { Component } from 'react'
import ReactDOM from 'react-dom'


class App extends Component {
  state = {
    msg: 'Hello',
    msg2: '',
    city: 3,
    agree: false
  }
  render() {
    return <div>
      <h1>受控组件</h1>
      {/* input框通过value值控制 */}
      <input type="text"
        onChange={this.ipt}
        value={this.state.msg}
      />
      <h3>文本域</h3>
      <textarea
        value={this.state.msg2}
        onChange={this.ipt2}
        name=""
        id=""
        cols="30"
        rows="10">
      </textarea>
      <h3>下拉框</h3>
      <select onChange={this.changeS} value={this.state.city}>
        <option value="1">北京</option>
        <option value="2">上海</option>
        <option value="3">武汉</option>
      </select>
      <div>
        <label htmlFor="y">是否同意我们的协议</label>
        <input onChange={this.changeAgree} checked={this.state.agree} id='y' type="checkbox" />
      </div>

    </div>
  }
  ipt = (e) => {
    console.log(this.state.msg);
    this.setState({
      msg: e.target.value
    })
  }
  ipt2 = (e) => {
    this.setState({
      msg2: e.target.value
    })
  }
  changeS = (e) => {
    console.log(this.state.city);
    this.setState({
      city: e.target.value
    })
  }
  changeAgree = (e) => {
    console.log(this.state.agree);
    this.setState({
      agree: e.target.checked
    })
  }
}

ReactDOM.render(<App></App>, document.getElementById('root'))